<style>
    .input-require {
        color: red;
    }

    .layui-form-select {
        color: #c2c2c2;
    }

    .layui-input {
        color: #c2c2c2;
        border-radius: 4px;
    }

    .layui-form-select dl dd.layui-this {
        background-color: #FF6C60;
    }

    .layui-laydate .layui-this {
        background-color: #FF6C60 !important;
    }

</style>

<div class="row">
    <div class="col-lg-12">
        <section class="panel">
            <header class="panel-heading">
                {$HandleName}
            </header>
            <div class="panel-body">
                <form id="form" class="layui-form form-horizontal tasi-form " method="get">
                    <div class="form-group" style="display: none">
                        <label class="col-sm-2 control-label">处理类型</label>
                        <div class="col-sm-10">
                            <input name="HandleType" type="text" class="form-control" value="{$HandleType}">
                        </div>
                    </div>
                    <div class="form-group" style="display: none">
                        <label class="col-sm-2 control-label">账户ID</label>
                        <div class="col-sm-10">
                            <input name="ID" type="text" class="form-control" value="{$User['ID']}">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">账号<span class="input-require">*</span></label>
                        <div class="col-sm-10">
                            <input name="Name" type="text" class="form-control" value="{$User['Name']}"
                                   {$HandleType=='Edit'?'disable':'required lay-verify="required"'}>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">名称<span class="input-require">*</span></label>
                        <div class="col-sm-10">
                            <input name="Nick" type="text" class="form-control" value="{$User['Nick']}" required
                                   lay-verify="required">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">密码{$HandleType=='Add'?'<span
                                class="input-require">*</span>':''}</label>
                        <div class="col-sm-10">
                            <input name="Password" type="password" class="form-control" value=""
                                   {$HandleType=='Edit'?'placeholder="不修改則留空"':'required lay-verify="required"'}>
                        </div>
                    </div>

                    <?php if($HandleType == 'Edit'){ ?>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">确认密码</label>
                        <div class="col-sm-10">
                            <input name="ComfirmPassword" type="text" class="form-control" value=""
                                   {$HandleType=='Edit'?'placeholder="不修改則留空"':''}>
                        </div>
                    </div>
                    <?php } ?>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">微信</label>
                        <div class="col-sm-10">
                            <input name="WeChat" type="text" class="form-control" value="{$User['WeChat']}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">QQ</label>
                        <div class="col-sm-10">
                            <input name="QQ" type="text" class="form-control" value="{$User['QQ']}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">电话号码</label>
                        <div class="col-sm-10">
                            <input name="Phone" type="text" class="form-control" value="{$User['Phone']}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">Email</label>
                        <div class="col-sm-10">
                            <input name="Email" type="email" class="form-control" value="{$User['Email']}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">性别</label>
                        <div class="col-sm-10">
                            <select name="Sex" class="form-control m-bot15">
                                <?php
                                for($i=0; $i<3; $i++){
                                    $OptionName = '请选择';
                                    switch($i){
                                        case 1: $OptionName = '男';
                                            break;
                                        case 2: $OptionName = '女';
                                            break;
                                        default:break;
                                    }
                                    $OptionStatus = '';
                                    if($i==$User['Sex']){
                                        $OptionStatus = 'selected';
                                    }
                                    echo "<option value='$i' $OptionStatus > $OptionName </option>";
                                }
                                ?>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">备注</label>
                        <div class="col-sm-10">
                            <textarea name="Remark" class="form-control" cols="60" rows="5">{$User['Remark']}</textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">所属企业</label>
                        <div class="col-sm-10">
                            <select name="CompanyID" class="form-control m-bot15" lay-filter="CompanyID">
                                <?php
                                if($User['CompanyID'] == '0') $OptionStatus = 'selected';
                                echo "<option value='0' $OptionStatus >请选择</option>";

                                for($i=0; $i<count($Companys); $i++){
                                    $Value = $Companys[$i];
                                    $CompanyID = $Value['ID'];
                                    $Name = $Value['Name'];

                                    $OptionStatus = '';
                                    if($CompanyID==$User['CompanyID']){
                                        $OptionStatus = 'selected';
                                    }
                                    echo "<option value='$CompanyID' $OptionStatus> $Name</option>";
                                }
                                ?>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">所属部门</label>
                        <div class="col-sm-10">
                            <select id="DepartmentID" name="DepartmentID" class="form-control m-bot15"
                                    lay-filter="DepartmentID">
                                <option value='0' selected>请选择</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">所属职位</label>
                        <div class="col-sm-10">
                            <select id="PostID" name="PostID" class="form-control m-bot15" lay-filter="PostID">
                                <option value='0' selected>请选择</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">直接上級</label>
                        <div class="col-sm-10">
                            <select id="SuperiorID" name="SuperiorID" class="form-control m-bot15"
                                    lay-filter="SuperiorID">
                                <option value='0' selected>请选择</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-10">
                            <button class="btn btn-primary" lay-submit lay-filter="formSubmit">立即提交</button>
                            <button type="reset" class="btn btn-info">重置</button>
                        </div>
                    </div>

                </form>
            </div>
        </section>
    </div>
</div>

<script>
    layui.use(['form', 'laydate'], function () {
        var form = layui.form,
            laydate = layui.laydate;
        laydate.render({
            elem: '#TimeRegist',
            type: 'date'
        });
        form.on('submit(formSubmit)', function (data) {
            var fields = data.field;
            global.log('系統設定 - 提交數據', fields);
            global.post('/index.php/superadmin/Company_User/mb_SubmitUser', fields, function (msg) {
                if (msg['code'] == ErrCode_Normal) {
                    layer.msg(msg['msg'], {
                        offset: '15px'
                        , icon: 1
                        , time: 1000
                    }, function () {
                        window.location.reload();
                    });
                } else mb_OnMessage(msg);
            });
            return false;
        });

        form.on('select(CompanyID)', function (data) {
            var field = {
                CompanyID: data.value
            };
            global.post('/index.php/superadmin/Company_User/mb_GetDepartments', field, function (msg) {
                if (msg['code'] == ErrCode_Normal) {
                    $("#DepartmentID").find('option').remove();
                    $("#DepartmentID").append("<option value='0'>请选择</option>");
                    for (var i = 0; i < msg['data'].length; i++) {
                        var val = msg['data'][i];
                        $("#DepartmentID").append("<option value='" + val.ID + "'>" + val.Name + "</option>");
                    }
                    layui.form.render("select");//重新渲染 固定写法

                    return false;
                } else {
                    // mb_OnMessage(msg);
                    return false;
                }
            });
            global.post('/index.php/superadmin/Company_User/mb_GetCompanyUsers', field, function (msg) {
                if (msg['code'] == ErrCode_Normal) {
                    $("#SuperiorID").find('option').remove();
                    $("#SuperiorID").append("<option value='0'>请选择</option>");
                    for (var i = 0; i < msg['data'].length; i++) {
                        var val = msg['data'][i];
                        $("#SuperiorID").append("<option value='" + val.ID + "'>" + val.Nick + "</option>");
                    }
                    layui.form.render("select");//重新渲染 固定写法

                    return false;
                } else {
                    return false;
                }
            })
        })
        form.on('select(DepartmentID)', function (data) {
            var field = {
                DepartmentID: data.value
            };
            global.post('/index.php/superadmin/Company_User/mb_GetPosts', field, function (msg) {
                if (msg['code'] == ErrCode_Normal) {
                    $("#PostID").find('option').remove();
                    $("#PostID").append("<option value='0'>请选择</option>");
                    for (var i = 0; i < msg['data'].length; i++) {
                        var val = msg['data'][i];
                        $("#PostID").append("<option value='" + val.ID + "'>" + val.Name + "</option>");
                    }
                    layui.form.render("select");//重新渲染 固定写法

                    return false;
                } else {
                    // mb_OnMessage(msg);
                    return false;
                }
            })
        })
    });
    
    function mb_() {
        
    }
</script>